package com.qinggeng.project.system.controller;

import com.qinggeng.common.enums.ShowTypeEnum;
import com.qinggeng.common.enums.UserTypeEnum;
import com.qinggeng.common.utils.SecurityUtils;
import com.qinggeng.common.utils.StringUtils;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.system.domain.Goods;
import com.qinggeng.project.system.domain.GoodsMark;
import com.qinggeng.project.system.service.IGoodsMarkService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/mark")
public class GoodsMarkController extends BaseController {

    @Autowired
    private IGoodsMarkService goodsMarkService;

    /**
     * 修改商品标签列表
     */
    @GetMapping("/list")
    public TableDataInfo list() {
        List<GoodsMark> goodsMarkList=goodsMarkService.selectGoodsMarkList();
        return getDataTable(goodsMarkList);
    }

    /**
     * 新增商品标签
     */
    @PreAuthorize("@ss.hasPermi('system:goodsMark:new')")
    @PostMapping
    public AjaxResult add(GoodsMark goodsMark) {
        if(StringUtils.isEmpty(goodsMark.getId())){
            return AjaxResult.error("标签ID不能为空", ShowTypeEnum.用户.getValue());
        }else{
            GoodsMark oldGoodsMark=goodsMarkService.selectGoodsMarkById(goodsMark.getId());
            if(oldGoodsMark!=null){
                return AjaxResult.error("标签ID已存在！",ShowTypeEnum.用户.getValue());
            }
        }
        if(StringUtils.isEmpty(goodsMark.getMark())){
            return AjaxResult.error("商品标签不能为空", ShowTypeEnum.用户.getValue());
        }
        return toAjax(goodsMarkService.insertGoodsMark(goodsMark));
    }

    /**
     * 添加商品标签列表
     */
    @PreAuthorize("@ss.hasPermi('system:goodsMark:edit')")
    @PutMapping
    public AjaxResult update(GoodsMark goodsMark) {
        return toAjax(goodsMarkService.updateGoodsMark(goodsMark));
    }

    /**
     * 删除商品标签列表
     */
    @PreAuthorize("@ss.hasPermi('system:goodsMark:delete')")
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable String id) {
        return toAjax(goodsMarkService.deleteGoodsMarkById(id));
    }




}
